import request from '../utils/axios';

export const getUsers = () => request.get('/user/users', {});

// 替换为 api 实例而不是 request

export const addUser = (data) => request.post('/user/users', data);

export const updateUser = (data) => request.put(`/user/users`, data);

export const deleteUser = (userId) => request.delete(`/user/users/${userId}`);

/**
 * 上传用户头像
 * @param {File} file - 要上传的图片文件
 * @returns Promise
 */
export const uploadAvatar = (file) => {
  const token = localStorage.getItem('token');
  const formData = new FormData();
  formData.append('file', file);

  return request.post('/user/avatar', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
      Authorization: `Bearer ${token}`, // 推荐使用 Bearer 格式
    },
  });
};
